<?php

class ProductOption extends DataObject {

    static $singular_name = 'Product Option';	
    static $plural_name = 'Product Options';

    static $db = array(
        'Title' => 'Varchar(255)'
    );
    
    static $has_many = array(
        'Options' => 'OptionValue'
    );
    
    static $belongs_many_many = array(
        'Products' => 'Product'
    );

    function getCMSFields_forPopup() {
        $fields = new FieldSet();
        $fields->push( new TextField( 'Title' ) );
        return $fields;
    }

    function getCMSFields() {
        $fields = parent::getCMSFields();
        $fields->addFieldToTab('Root.Main', new TextField('Title'));

        $tablefield = new HasManyComplexTableField(
            $this,
            'Options',
            'OptionValue',
                array(
                    'Option' => 'Option',
                ),
            'getCMSFields_forPopup'
        );
        $tablefield->setAddTitle( 'an option' );

        $fields->addFieldToTab( 'Root.Main', $tablefield );

        return $fields;
    }
}